package io.bluefw.microapp.auth.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import io.bluefw.microapp.core.Globalize;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "AUT_Account")
@Globalize(value = "用户")
public class Account {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    @Column(length=32, nullable=false)
    @Globalize(value = "邮箱")
    private String email;
    
    @Column(length=16, nullable=false)
    @Globalize(value = "用户名")
    private String name;
    
    @Column(length=128, nullable=false)
    @Globalize(value = "密码")
    private String password;
    
    @Column(length=24, nullable=false)
    @Globalize(value = "盐值")
    private String salt;
    
    @ManyToMany(cascade = CascadeType.REMOVE)
    @JoinTable(
    		name = "AUT_Account_Role",
    		joinColumns = @JoinColumn(name = "account_id"),
    		inverseJoinColumns = @JoinColumn(name = "role_id")
    )
	private List<Role> roles;
}
